
*******************************************************************************************************************
* Description: Analysis for 'The origins of centralized agenda control at Westminster: Consensus or controversy?'
*              Legislative Studies Quarterly, 2024
* Authors:     Thomas Fleming, Simon Hix, and Radoslaw Zubek
* Date:        12/09/2024
* Note:        Requires "votes_parliament_27.csv" and "speeches.xlsx"
*******************************************************************************************************************

clear

*******************************************************
* Loading voting data, dropping and sorting variables *
*******************************************************

  import delimited "votes_parliament_27.csv"

  drop mpsname mpfname mpdob
  
  order d*, alphabetic last /* ensures divisions are in chronological sequence */

*****************************************************************************************
* Standardizing direction of voting: 1 = voting with the government; 0 = voting against *
*****************************************************************************************

* loops over all division variables

  foreach var of varlist d* {
		
* counts how many government MPs (Con and Lib Unionist) voted Aye and No in each division
		
    quietly count if (mpparty_at_start == "C" | mpparty_at_start == "LU") & `var' == 1
	local gov_aye = r(N)
	quietly count if (mpparty_at_start == "C" | mpparty_at_start == "LU") & `var' == 0
	local gov_no = r(N)
	
* where there is no majority government position, displays a warning
	
	if `gov_aye' == `gov_no' {
		display "WARNING. Division `var': no government majority position, with `gov_aye' voting Aye and `gov_no' voting No."
	}
	
* where the government majority position was No, recodes all votes so that 1 indicates that position
	
	else if `gov_no' > `gov_aye' {
		quietly recode `var' (1=0) (0=1) 
		display "Division `var': direction recoded, with `gov_no' government MPs voting 'No' and `gov_aye' voting 'Aye'.
	}
  }
	
**********************************************************************************************
* Calculating Liberal position and Rice score in nine Balfour reform divisions (for Table 1) *
**********************************************************************************************

* loops over nine Balfour reform divisions

  foreach var of varlist d20413 d20414 d20417 d20418 d20419 d20420 d20422 d20423 d20425 {
  	
* counts the total number of Liberal MPs voting, and the number voting with and against the government position
	
  	quietly count if mpparty_at_start == "L" & `var' != .
	local libs_voting_total = r(N)
	quietly count if mpparty_at_start == "L" & `var' == 1
	local libs_voting_for_gov = r(N)
	quietly count if mpparty_at_start == "L" & `var' == 0
	local libs_voting_against_gov = r(N)
	
* calculates the Liberal Party Rice score
	
	local rice_score = abs(`libs_voting_for_gov' - `libs_voting_against_gov') / `libs_voting_total'
	
* displays the results of the above calculations
	
	display "Division `var': `libs_voting_total' Liberal MPs voted, of which `libs_voting_for_gov' voted with the government and `libs_voting_against_gov' voted against the government. Rice Score = `rice_score'"
  }

*****************************************************************************************
* Calculating raw vote figures by party in nine Balfour reform divisions (for Table A3) *
*****************************************************************************************

* produces simplified party variable
  	
  gen party_simple = mpparty_at_start

  replace party_simple = "Other" if party_simple != "C" & party_simple != "LU" & party_simple != "L" & party_simple != "N"
  
* reports this for each of the nine divisions

  foreach var of varlist d20413 d20414 d20417 d20418 d20419 d20420 d20422 d20423 d20425 {
	tab party_simple `var', missing
  }
  
***********************************************************************************************************
* Calculating Liberal Rice scores and turnout numbers in earlier gov vs. opposition votes (for main text) *
***********************************************************************************************************
  
* restricting to divisions from the 1901 session (d19844-20322)

  drop d19828-d19843 /* dropping divisions from the short 1900 post-election session */
  drop d20323-d21939 /* dropping all divisions after the end of the 1901 session */

* showing total number of variables (of which all but five are divisions)
  
  describe
  
* restricting to divisions where the majority of voting Liberals opposed the government position
  
  foreach var of varlist d* {
  
    quietly count if (mpparty_at_start == "C" | mpparty_at_start == "LU") & `var' == 1
	local gov_aye = r(N)
	quietly count if (mpparty_at_start == "C" | mpparty_at_start == "LU") & `var' == 0
	local gov_no = r(N)
  
    if `gov_aye' == `gov_no' {
		display "WARNING. Division `var': no government majority position, with `gov_aye' voting one way and `gov_no' voting another."
	}
  
  	quietly count if mpparty_at_start == "L" & `var' == 1
	local libs_voting_for_gov = r(N)
	quietly count if mpparty_at_start == "L" & `var' == 0
	local libs_voting_against_gov = r(N)
	
	if `libs_voting_against_gov' == `libs_voting_for_gov' drop `var'  /* excludes even splits in Liberals */
	if `libs_voting_against_gov' < `libs_voting_for_gov' drop `var'   /* excludes cases of government support */
	
  }	
  
* restricting to only Liberal MPs and reshaping to long format

  drop if mpparty_at_start != "L"
  
  reshape long d, i(mpid mpname mpparty_at_start mpparty_at_end) j(division) 
  
  sort division
  
* reformatting vote variable for clarity
  
  rename d vote
  label define voting_label 0 "Against government" 1 "With government"
  label values vote voting_label
  
* calculating numbers of Liberal MPs voting in total and each way in each division

  egen libs_voting_total = total(vote != .), by(division) 
  
  egen libs_voting_with_gov = total(vote == 1), by(division)

  egen libs_voting_against_gov = total(vote == 0), by(division)
  
* calculating Rice score

  gen rice = abs(libs_voting_with_gov - libs_voting_against_gov) / libs_voting_total
  
* restricting to just one observation per division, and dropping MP-specific variables

  bysort division: keep if _n==1
  
  keep division libs* rice
  
* calculating mean and median turnout numbers and Rice scores

  sum libs_voting_total, detail
  
  sum rice, detail

  tab rice
  
**********************************************************
* Loading speech data and reformatting to MP-level *
**********************************************************

  clear
  
  import excel "speeches.xlsx", firstrow
  
* reducing to one observation per MP-division dyad
  
  bysort division_id mp_name: keep if _n==1
  
  drop key_quote speech
  
  drop if mp_name == "Mr Speaker"

**************************************************
* Showing Liberal speech positions (for Table 2) *
**************************************************
  
* simplifying party labels

  gen party_simple = party_at_start

  replace party_simple = "Other" if party_simple != "C" & party_simple != "LU" & party_simple != "L" & party_simple != "N"
  
* cross-tab of speech position and each amendment, Liberals only

  tab division_id speeches_position if party_simple == "L"
  
***********************************************************
* Showing speech positions for all parties (for Table A4) *
***********************************************************
 
* cross-tab of party affiliation and speech position

  tab party_simple speeches_position
  
  clear
  